/**
 * Copyright (c) 华南农业大学信息学院蔡超敏2015版权所有
 * 
 * 文件创建时间：2015年7月7日
 */
package org.scauinfo.fpos.service.impl;

import java.io.Serializable;
import java.util.List;

import org.scauinfo.fpos.dao.impl.TableplateDao;
import org.scauinfo.fpos.service.TableplateService;
import org.scauinfo.fpos.vo.Tableplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 蔡超敏
 * 
 */
@Service
public class TableplateServiceImpl implements TableplateService {

	@Autowired
	private TableplateDao tableplateDao;

	@Override
	public void saveTableplate(Tableplate tableplate) {
		tableplateDao.save(tableplate);
	}

	@Override
	public void updateTableplate(Tableplate tableplate) {
		tableplateDao.update(tableplate);
	}

	@Override
	public void deleteTableplate(int id) {
		Tableplate tableplate = tableplateDao.get(id);
		tableplate.setSaleorders(null);
		tableplateDao.delete(tableplate);
	}

	@Override
	public List<Tableplate> findAllTableplate(int page, int rows, String sort,
			String order) {
		return tableplateDao.findAll(page, rows, sort, order);
	}

	@Override
	public int getTotal() {
		return tableplateDao.countAll();
	}

	@Override
	public boolean isExist(String TableplateId) {
		boolean flag = false;
		String hql = "from Tableplate as p where p.TableplateId="
				+ TableplateId;
		if (tableplateDao.find(hql).size() > 0) {
			flag = true;
		}
		return flag;
	}

	@Override
	public List<Tableplate> findAllTableplate() {
		return tableplateDao.findAll();
	}

	@Override
	public List<Tableplate> findAllUsableTableplate() {
		String hql = "from Tableplate as p where p.tableState=" + 0;

		return tableplateDao.find(hql);
	}

	@Override
	public Tableplate get(Serializable id) {
		return tableplateDao.get(id);
	}

}